// 将参数转化为formData格式
export const replaceFormData = (data) => {
  const formData = new FormData();
  for (const key in data) {
    if (data[key] || String(data[key]) === "0") {
      formData.append(key, data[key]);
    }
  }
  return formData;
};
// 处理审批人
export const disPerson = (ids, personList) => {
  if (!ids) return [];
  const arr = ids.split(",");
  let pserson = [];
  personList.forEach((item) => {
    item.cimContactsVOList.forEach((it) => {
      if (arr.includes(it.personId)) {
        pserson.push([item.orgId, it.personId]);
      }
    });
  });
  return pserson;
};

// 获取级联选择的数据中的人员id
export const getIdsData = (idArr, personList, type) => {
  let ids = [];
  let names = [];
  if (type === "select") {
    ids = idArr;
    names = personList.map((item) => {
      if (ids.includes(item.personId)) {
        return item.name;
      }
    });
  } else {
    ids = idArr.map((item) => item[1]);
    names = [];
    ids.forEach((item) => {
      personList.forEach((t) => {
        t.cimContactsVOList.forEach((v) => {
          if (v.personId === item) {
            names.push(v.name);
          }
        });
      });
    });
  }
  const idStr = ids.join(",");
  const nameStr = names.join(",");
  return {
    idStr,
    nameStr,
  };
};
